<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/6
 * Time: 19:17
 */

namespace App;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class VipCard extends Model
{
    // 开启软删除
    use SoftDeletes;
    // 表名称
    protected $table = 'vip_card';
    // 开启自动时间戳
    public $timestamps = true;
    // 日期都存储为时间戳
    protected $dateFormat = 'U';

    // 将面额单位从元换算成分
    public function setDenominationAttribute($value)
    {
        $this->attributes['denomination'] = $value*100;
    }

    // 将面额单位从分换算成元
    public function getDenominationAttribute($value)
    {
        return $value/100;
    }

    // 将最低续费单位从元换算成分
    public function setMinimumRechargeAttribute($value)
    {
        $this->attributes['minimum_recharge'] = $value*100;
    }

    // 将最低续费单位从分换算成元
    public function getMinimumRechargeAttribute($value)
    {
        return $value/100;
    }

    public function vipCardRule()
    {
        return $this->belongsToMany('App\VipCardRule', 'vip_card_rule_value', 'vip_card_id', 'vip_card_rule_id');
    }

    public function vipCardRuleValue()
    {
        return $this->hasMany('App\VipCardRuleValue', 'vip_card_id', 'id');
    }
}